package com.menu.Controller;

import com.menu.Pojo.Ingredients;
import com.menu.Pojo.SecurityUser;
import com.menu.Pojo.Step;
import com.menu.Service.MenuFatherService;
import com.menu.Utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "菜单接口")
public class MenuFatherController {
    @Resource
    MenuFatherService menuFatherService;


    @ApiOperation(value = "用户上传菜单")
    @PostMapping("/User/addMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "menuFatherName", value = "菜单名字", required = true),
                    @ApiImplicitParam(name = "menuFatherIntroduce", value = "菜单介绍", required = true),
                    @ApiImplicitParam(name = "menuIds", value = "食谱id数组",allowMultiple = true, dataTypeClass = List.class,required = true),
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
            }
    )
    public ResponseResult addMenu(String menuFatherName, String menuFatherIntroduce,
                                  Integer[] menuIds, Integer userId,@RequestPart("menuFatherSrc") MultipartFile menuFatherSrc){
        return menuFatherService.addMenuFather(menuFatherName, menuFatherIntroduce, menuIds, userId, menuFatherSrc);
    }



    @ApiOperation(value = "遍历所有菜单--后台")
    @GetMapping("/Admin/findAllMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
            }
    )
    public ResponseResult findAllMenuFather(Integer pageNow,Integer pageSize){
        return menuFatherService.findAllMenuFather(pageNow, pageSize);
    }


    @ApiOperation(value = "遍历某菜单下所有食谱")
    @GetMapping("/Visitor/findMenuByMenuFatherMenuIds")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "MenuFatherId", value = "菜单id", required = true)
            }
    )
    public ResponseResult findMenuByMenuFatherMenuIds(Integer MenuFatherId){
        return menuFatherService.findMenuByMenuFatherMenuIds(MenuFatherId);
    }


    @ApiOperation(value = "最新的菜单--填写几天内")
    @GetMapping("/Visitor/findAllNearTimeMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true),
                    @ApiImplicitParam(name = "day", value = "天数", required = true)
            }
    )
    public ResponseResult findAllNearTimeMenuFather(Integer pageNow,Integer pageSize,Integer day){
        return menuFatherService.findAllNearTimeMenuFather(pageNow, pageSize, day);
    }


    @ApiOperation(value = "最热的菜单")
    @GetMapping("/Visitor/findByMenuFatherByDoh")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true)
            }
    )
    public ResponseResult findByMenuFatherByDoh(Integer pageNow,Integer pageSize){
        return menuFatherService.findByMenuFatherByDoh(pageNow, pageSize);
    }


    @ApiOperation(value = "单个删除菜单")
    @DeleteMapping("/User/deleteMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "menuFatherId", value = "菜单id", required = true),
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true)
            }
    )
    public ResponseResult deleteMenuFather(Integer menuFatherId,Integer userId){
        return menuFatherService.deleteMenuFather(menuFatherId,userId);
    }

    @ApiOperation(value = "批量删除菜单")
    @DeleteMapping("/User/batchDeleteMenuFather")
    public ResponseResult batchDeleteMenuFather(Integer []menuFatherId){
        return menuFatherService.batchDeleteMenuFather(menuFatherId);
    }


    @ApiOperation(value = "遍历某用户下的菜单")
    @GetMapping("/Visitor/findMenuFatherByUserId")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "pageNow", value = "当前页数", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "一页几条", required = true)
            }
    )
    public ResponseResult findMenuFatherByUserId(Integer pageNow,Integer pageSize,Integer userId){
        return menuFatherService.findMenuFatherByUserId(userId,pageNow, pageSize);
    }


    @ApiOperation(value = "审核菜单")
    @PostMapping("/Admin/verifyMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "menuFatherId", value = "菜谱id", required = true),
                    @ApiImplicitParam(name = "state", value = "只能填-1或者1，-1不通过，1通过", required = true),
            }
    )
    public ResponseResult verifyMenuFather(Integer menuFatherId,Integer state){
        return menuFatherService.verifyMenuFather(menuFatherId, state);
    }


    @ApiOperation(value = "在菜单中添加菜谱")
    @PutMapping("/User/addMenuAtMenuFather")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "menuFatherId", value = "菜谱id", required = true),
                    @ApiImplicitParam(name = "menuId", value = "食谱id", required = true),
            }
    )
    public ResponseResult addMenuAtMenuFather(@ApiIgnore @AuthenticationPrincipal SecurityUser securityUser, Integer menuId, Integer menuFatherId){
        return menuFatherService.addMenuAtMenuFather(securityUser.getUserId(), menuId, menuFatherId);
    }

}
